<template>
  <div id="">
    <wxc-popup width="500"
                 :show="showList"
                 @wxcPopupOverlayClicked="listClose"
                 pos="right">
      <scroller class="container" :style="scrollerStyle">
        <div class="list">
            <div class="policyCell"  v-for="(item,index) in formItem" :key="index">
                <wxc-cell @wxcCellClicked="wxcCellClicked" title="电梯工号" :cell-style="cellStyle">
                <text :style="valueStyle">{{item.number}}</text>
                </wxc-cell>

                <wxc-cell @wxcCellClicked="gotoDetail(item)" :has-arrow="true" title="工单编号" :cell-style="cellStyle">
                <text :style="valueStyle">{{item.upkeepNumber}}</text>
                </wxc-cell>

                <wxc-cell title="维保日期" :cell-style="cellStyle">
                <text :style="valueStyle">{{item.upkeepDate}}</text>
                </wxc-cell>

                <wxc-cell @wxcCellClicked="wxcCellClicked"
                        :has-margin="true" :has-bottom-border="false" title="工单状态" :cell-style="cellStyle">
                <text :style="valueStyle">{{getPolicyStatus(item)}}</text>
                </wxc-cell>
            </div>
            <text class='text-no' v-if="formItem.length<=0" >暂无数据</text>
        </div>
      </scroller>
      <wxc-loading :show="showLoading" :need-mask="mask"></wxc-loading>
    </wxc-popup>
    
  </div>
</template>
<script>
  import { WxcCell,WxcPopup,WxcSearchbar,WxcLoading,Utils} from 'weex-ui';
  import util from '../utils/util';
  export default {
    components: { WxcCell,WxcPopup,WxcSearchbar,WxcLoading,Utils},
    props: {
      showList:{
        default:false
      },
    },
    data: () => ({
      token:'',
      formItem:[],
      valueStyle:{
        color:'rgb(153, 153, 153)',
      },
      cellStyle:{
        height:'70px'
      },
      mask:true,
    }),
    methods: {
      listClick(e) {
        this.$router.open({
            name: e
        })
      },
      listClose(){
        this.formItem = []
        this.$emit('closeList')
      },
      getPolicyStatus (item) {
        if (item.status === 0) {
          return '未接单'
        } else if (item.status === 1) {
          return '已接单'
        } else if (item.status === 3) {
          return '退单'
        } else if (item.status === 2 && !item.signature2) {
          return '待签字'
        } else if (item.status === 2 && item.signature2) {
          return '已签字'
        } else {
          return '其他'
        }
      },
      getPolicyList(status,yearMonth){
          this.showLoading = true
          var filter = {}
          filter.year = yearMonth.substring(0, 4)
          filter.month = yearMonth.substring(5, 7)
          filter.status = status
          this.$fetch({
              header:{
                    'Content-Type': 'application/x-www-form-urlencoded',
                    'Authorization': `Bearer `+ this.token
              },
              method: 'POST',    
              name: 'monthUpkeepList',
              data: filter
          }).then(res => {
              if(res.success){
                 this.formItem = res.data ? res.data : []
              }else{
                this.$notice.toast({
                  message: '网络错误'
                })
              }
          }, error => {
              this.$notice.toast({
                  message: '网络错误'
              })
          })
          this.showLoading = false
      },
      getMyUpkeepList(startDate){
          this.showLoading = true
          var filter = {}
          filter.startDate = startDate
          filter.endDate = startDate
          this.$fetch({
              header:{
                    'Content-Type': 'application/x-www-form-urlencoded',
                    'Authorization': `Bearer `+ this.token
              },
              method: 'POST',    
              name: 'listMyUpkeep',
              data: filter
          }).then(res => {
              if(res.success){
                this.formItem = res.data ? res.data : []
              }else{
                this.$notice.toast({
                  message: '网络错误'
                })
              }
          }, error => {
              this.$notice.toast({
                  message: '网络错误'
              })
          })
          this.showLoading = false
      },
      //保单详情页
      gotoDetail(item){
          this.showLoading = true
          let filter = {}
          filter.upkeepId = item.upkeepId
          this.$fetch({
              header:{
                  'Content-Type': 'application/x-www-form-urlencoded',
                  'Authorization': `Bearer `+ this.token
              },
              method: 'POST',    
              name: 'getUpkeepDetail',
              data: filter
          }).then(resData => {
              if(resData.success){
                  this.$storage.set('upkeepDetail_'+item.id, JSON.stringify(resData.data))
                  this.showLoading = false
                  //跳转详情页
                  this.$router.open({
                      name: 'maintenaceDetail',
                      params:{upkeepId:item.id}
                  })
              }else{
                  this.$notice.toast({
                      message: '网络错误'
                  })
              }
          }, error => {
              // this.$notice.toast({
              //     message: '网络错误'
              // })
          })
          this.showLoading = false
          
      },

      
    },
    created(){
      const tabPageHeight = Utils.env.getPageHeight()
      this.scrollerStyle ={ height: tabPageHeight + 'px' }
      //获取token
      this.token = this.$storage.getSync('token')
      if(!this.token){
          this.$router.setHomePage('/pages/login.js')
      }
    }
  }
</script>
<style scoped>
.container {
    background-color: #f2f3f4;
}
.text-no{
  text-align: center;
  margin-top: 100;
  font-size: 35;
  color: #999999
}
</style>
